package com.wang.vedio.player;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.google.gson.Gson;
import com.vondear.rxtool.view.RxToast;
import com.wang.vedio.R;
import com.wang.vedio.base.BaseActivity;
import com.wang.vedio.net.entity.BaseBean;
import com.wang.vedio.net.entity.LoginBean;
import com.wang.vedio.net.rxjava.HttpMethods;
import com.wang.vedio.net.subscribers.ProgressSubscriber;
import com.wang.vedio.net.subscribers.SubscriberOnNextListener;
import com.wang.vedio.utils.StringUtils;
import com.wang.vedio.utils.statusbar.StatusBarUtil;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class BussessHeZuoActivity extends BaseActivity {
    @BindView(R.id.contentEdit)
    EditText contentEdit;
    @BindView(R.id.phoneEdit)
    EditText phoneEdit;
    @BindView(R.id.sureBtn)
    TextView sureBtn;
    @Override
    protected int getLayoutId() {
        return R.layout.gyss_swhz_layout;
    }

    private int type;

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        setTitle("商务合作");
        StatusBarUtil.setStatusBar(this, true, R.color.transparent, false, true);
    }

    @Override
    protected void initData() {
    }

    private int page = 1;
    private void saveData() {
        SubscriberOnNextListener<BaseBean<LoginBean>> onNextListener = baseBean -> {
            RxToast.normal(baseBean.getMessage());
            finish();
        };
        Map<String, Object> params = new HashMap<>();
        params.put("content",contentEdit.getText().toString());
        params.put("linkInfo",phoneEdit.getText().toString());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), new Gson().toJson(params));
        HttpMethods.getInstance().addBusiness(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }

    @OnClick({R.id.sureBtn})
    public void onClick(View v){
        if(v.getId() == R.id.sureBtn){
            if(StringUtils.isEmpty(contentEdit.getText().toString())){
                RxToast.normal("请输入内容");
                return;
            }
            if(StringUtils.isEmpty(phoneEdit.getText().toString())){
                RxToast.normal("请输入联系方式");
                return;
            }
            saveData();
        }
    }
}
